package org.jeecg.modules.app;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.modules.market.entity.CompanyPurchase;
import org.jeecg.modules.market.service.ICompanyPurchaseService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Api(tags="index 李梅 小程序")
@RestController
@RequestMapping("/app")
public class AppIndexController {
    @Autowired
    private ICompanyPurchaseService companyPurchaseService;
    @Autowired
    private ISysUserService sysUserService;
    @ApiOperation(value="首页-收购 分页", notes="首页-收购 分页")
    @GetMapping(value = "/queryPurchasePagelist")
    public Result<IPage<CompanyPurchase>> queryPurchasePagelist(CompanyPurchase companyPurchase,
                                                        @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                        @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                        HttpServletRequest req) {
        Result<IPage<CompanyPurchase>> result = new Result<IPage<CompanyPurchase>>();
        QueryWrapper<CompanyPurchase> queryWrapper = QueryGenerator.initQueryWrapper(companyPurchase, req.getParameterMap());
        Page<CompanyPurchase> page = new Page<CompanyPurchase>(pageNo, pageSize);
        IPage<CompanyPurchase> pageList = companyPurchaseService.page(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }

    @ApiOperation(value="李梅小程序-我的", notes="李梅小程序-我的")
    @GetMapping(value = "/summaryPersonSelf")
    public Result<?> summaryPersonSelf(){
        String  openid = JwtUtil.getUsername(TokenUtils.getTokenByRequest());
        SysUser sysUser = sysUserService.getUserByName(openid);
        if (ObjectUtil.isEmpty(sysUser)){

        }
        return Result.ok();
    }


}
